package cn.jingyuan.swan.cloud.mapping;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.util.AntPathMatcher;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * SpringMvc ApiResourceScanHandler 实现
 */
public class SpringMvcApiResourceScanHandler extends AbstractApiResourceScanHandler implements ApplicationListener<ContextStartedEvent> {

    private final AntPathMatcher PATH_MATCHER = new AntPathMatcher();

    /** 忽略的资源 */
    protected final List<String> IGNORE_URLS = new ArrayList<>();

    public SpringMvcApiResourceScanHandler() {
        super();
    }

    @Override
    public Collection<String> getIgnoreScanUrls() {
        return IGNORE_URLS;
    }

    @Override
    public void addIgnoreScanUrls(Collection<String> urls) {
        if (urls != null && !urls.isEmpty()) {
            // FIXME 校验 urls 的有效性
            IGNORE_URLS.addAll(urls);
        }
    }

    @Override
    public void onApplicationEvent(ContextStartedEvent event) {
        // FIXME 待实现
    }

}
